package geez.widget;

import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Widget;

import static geez.widget.Geez.withStyle;

public class GGrid<T extends GGrid> extends Grid implements GWidget, GTable {

    public GGrid(int rows, int columns) {
        super(rows, columns);
    }

    public T id(String id) {
        Geez.withNameAndId(this, id);
        return downcastSelft();
    }

    public T css(String cssClass, String... optionalClasses) {
        withStyle(this, cssClass, optionalClasses);
        return downcastSelft();
    }

    public T show() {
        setVisible(true);
        return downcastSelft();
    }

    public T hide() {
        setVisible(false);
        return downcastSelft();
    }


    public T cellspacing(int spacing) {
        setCellSpacing(spacing);
        return downcastSelft();
    }

    public T cellpadding(int padding) {
        setCellPadding(padding);
        return downcastSelft();
    }

    public T set(int row, int column, Widget widget) {
        setWidget(row, column, widget);
        return downcastSelft();
    }

    public T columnFormatter(ColumnFormatter formatter) {
        setColumnFormatter(formatter);
        return downcastSelft();
    }

    public T cellFormatter(CellFormatter formatter) {
        setCellFormatter(formatter);
        return downcastSelft();
    }

    private T downcastSelft() {
        //noinspection unchecked
        return (T) this;
    }


}